<?php
/**
 * Created by PhpStorm.
 * User: gxk
 * Date: 2019/4/27
 * Time: 21:22
 */
namespace Middleware;
defined('slim') or exit('访问不合法');
class LoginMiddleware
{
    public $ci;
    public function __construct($ci)
    {
        $this->ci = $ci;
    }

    /*
     * 验证登录中间件
     */
    public function __invoke($request, $response, $next)
    {
//        $response->getBody()->write('BEFORE');
        if (empty($_SESSION['member_name']) || empty($_COOKIE['member_id'])) {
            //身份验证
            $response = $response->withHeader('location', '/login');
        }
        $response = $next($request, $response);
//        $response->getBody()->write('AFTER');
        return $response;
    }
}